<?php

namespace app\admin\controller;

use app\common\model\AdminModel;
use think\facade\Cache;
use think\facade\Db;
use think\facade\View;

class IndexController extends Base
{

    protected $noLogin = ['test'];

    /**
     * 构造方法
     * @access public
     * @throws \Exception
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 框架首页
     * @return string
     * @throws \Exception
     */
    public function index()
    {
        $adminList = AdminModel::select();
        View::assign('admin_list',$adminList);
        return View::fetch();
    }

    public function changeLogin(){
        $adminModel = new AdminModel();
        $id = $this->request->param('id');
        $info = $adminModel->where('id',$id)->find()->toArray();
        $ret = $adminModel->setLoginInfo($info);
        cookie('system_token', $ret['token']);
        $this->success('操作成功');
    }

    /**
     * 系统主页
     * @return string
     */
    public function main()
    {
        $html = file_get_contents(app_path().'view/index/main.php');
        return View::display($html);
    }

    /**
     * 清空缓存
     */
    public function clear(){
        Cache::clear();
        $this->success('缓存已清除');
    }

    /**
     * 退出登录
     */
    public function quit()
    {
//        $a = cache::get('system_token-'.$this->loginInfo['id']);
//        echo $a;exit;
        //清除cookie
        Cache::delete('system_token-'.$this->loginInfo['id']);
        $this->result([],'退出成功',1);
    }
}
